package com.example.market.controller;

import com.example.market.pojo.ProductPicture;
import com.example.market.service.ProductPictureService;
import com.example.market.util.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/productPicture")
public class ProductPictureController {

    private JsonResponse jsonResponse;

    private ProductPictureService productPictureService;

    @Autowired
    public void setJsonResponse(JsonResponse jsonResponse) {
        this.jsonResponse = jsonResponse;
    }

    @Autowired
    public void setProductPictureService(ProductPictureService productPictureService) {
        this.productPictureService = productPictureService;
    }

    @GetMapping("/product/{productId}")
    public JsonResponse productPicture(@PathVariable String productId) {
        List<ProductPicture> productPictures = productPictureService.getProductPictureByProductId(productId);
        jsonResponse.success("001", productPictures);
        return jsonResponse;
    }

}